home *** CD-ROM | disk | FTP | other *** search
/ New Grand Theft Auto 2003 Classic Collection / PHOTOSHOP.iso / contents / sample.dxr / 00030_Display Text.ls < prev    next >
Encoding:
Text File  |  2002-04-19  |  9.5 KB  |  224 lines

  1. property spriteNum, getPDLError, myDisplayType, mySprite, myMember, myWidthAdjust, myHeightAdjust, myOffStageLoc, myoriginaleditablestate, myoriginallocz
  2.  
  3. on getBehaviorDescription me
  4.   return "DISPLAY TEXT" & RETURN & RETURN & "This behavior allows you to display a given string in a field or text member. " & "Use it with the Tooltip and Hypertext - Display Status behaviors which need a field or text member in which to display their information. " & "Or create your own custom Lingo to display runtime information, such as the position of the mouse." & RETURN & RETURN & "This behavior waits for Lingo commands to tell it what to do. " & "It is not active by itself." & RETURN & RETURN & "You can choose between two display types: tooltip and status bar." & RETURN & RETURN & "The TOOLTIP type of display will make the field or text member resize itself to fit the text, and disappear when it is empty. " & "You can set the tooltip type display to appear at any position on the stage, such as under the cursor. " & "If no position is sent to the sprite, it will appear at the top left corner of the Stage. " & "See the Tooltip behavior for more details." & RETURN & RETURN & "If you wish to display several lines of text, you must use RETURN characters to define the line breaks. " & "An empty tooltip sprite will move off-stage to hide. " & "It is recommended that you place it off-stage before it is used, in case it causes a brief flash on the screen." & RETURN & RETURN & "The STATUS BAR type of display will appear on Stage at all times. " & "It will not resize or change position. " & "Any positional information sent to this sprite will be ignored if it is set to act as a status bar. " & "If the text is too long to appear in the member of the current sprite, a scrollbar will appear. " & "You do not need to divide the text with RETURN characters. " & "If you think that a scrollbar may be necessary, make sure that the field or text member is sufficiently tall for the scroll arrows to operate correctly." & RETURN & RETURN & "Set the font size and other characteristics of the field or text member to customize the appearance of the message." & RETURN & RETURN & "Be sure to give the field or text member a name. " & "It may be emptied by this behavior. " & "Director automatically erases nameless empty members." & RETURN & RETURN & "PERMITTED MEMBER TYPES:" & RETURN & "field and text" & RETURN & RETURN & "PARAMETERS:" & RETURN & "* Display type:" & RETURN & "  - Tooltip (appears near the cursor on rollover)" & RETURN & "  - Status bar (appears in a fixed position at all times)" & RETURN & RETURN & "PUBLIC METHODS:" & RETURN & "* Set the text to display (and the position of the sprite)" & RETURN & RETURN & "ASSOCIATED BEHAVIORS:" & RETURN & "* Tooltip" & RETURN & "* Source Status" & RETURN & "* Hypertext - Display Status"
  5. end
  6.  
  7. on getBehaviorTooltip me
  8.   return "Use with field or text members." & RETURN & RETURN & "Waits for a message from another behavior or custom handler to display a character string. " & "This behavior is intended to be used with the Tooltip and Hypertext - Display Status behaviors to create a status bar or a tooltip under the cursor."
  9. end
  10.  
  11. on beginSprite me
  12.   myDisplayType = resolve(myDisplayType)
  13.   initialize(me)
  14. end
  15.  
  16. on endSprite me
  17.   mySprite.visible = 1
  18.   myMember.editable = myoriginaleditablestate
  19.   mySprite.locZ = myoriginallocz
  20. end
  21.  
  22. on resolve prop
  23.   case prop of
  24.     myDisplayType:
  25.       choiceslist = ["status bar (fixed size and position)", "tooltip (dynamic size and position)"]
  26.       lookup = [#statusbar, #tooltip]
  27.   end case
  28.   return lookup[findPos(choiceslist, prop)]
  29. end
  30.  
  31. on initialize me
  32.   mySprite = sprite(me.spriteNum)
  33.   myMember = mySprite.member
  34.   myoriginaleditablestate = myMember.editable
  35.   myoriginallocz = mySprite.locZ
  36.   myMember.editable = 0
  37.   if myMember.type = #field then
  38.     myWidthAdjust = (myMember.margin + myMember.border) * 2
  39.     myHeightAdjust = myMember.margin + (myMember.border * 2)
  40.   else
  41.     myWidthAdjust = 0
  42.     myHeightAdjust = 0
  43.   end if
  44.   myMember.text = EMPTY
  45.   if myDisplayType = #tooltip then
  46.     myMember.boxType = #fixed
  47.     myOffStageLoc = point(999, 999)
  48.     mySprite.loc = myOffStageLoc
  49.   end if
  50. end
  51.  
  52. on BestRect me, thestring
  53.   myMember.rect = rect(0, 0, 8000, 0)
  54.   myMember.text = thestring
  55.   BestRect = myMember.rect
  56.   theLine = the number of lines in thestring
  57.   theWidth = 0
  58.   checkedChars = 0
  59.   repeat while theLine
  60.     endOfLine = offset(RETURN, thestring)
  61.     if not endOfLine then
  62.       endOfLine = the number of chars in thestring + 1
  63.       myMember.text = myMember.text & RETURN
  64.     end if
  65.     checkedChars = checkedChars + endOfLine
  66.     endPoint = charPosToLoc(myMember, checkedChars)
  67.     lineWidth = endPoint[1]
  68.     if lineWidth > theWidth then
  69.       theWidth = lineWidth
  70.     end if
  71.     delete char 1 to endOfLine of thestring
  72.     theLine = theLine - 1
  73.   end repeat
  74.   lastChar = myMember.char.count
  75.   lastCharLoc = charPosToLoc(myMember, lastChar)
  76.   theHeight = lastCharLoc[2]
  77.   BestRect[3] = theWidth + 1
  78.   BestRect[4] = theHeight + 1
  79.   return BestRect
  80. end
  81.  
  82. on GetTopLeft me, theLoc, theAlignment, memberRect
  83.   case theAlignment of
  84.     #bottomcenter:
  85.       return theLoc - [memberRect.width / 2, memberRect.height]
  86.     #bottomright:
  87.       return theLoc - [memberRect.width, memberRect.height]
  88.     #bottomleft:
  89.       return theLoc - [0, memberRect.height]
  90.     #center:
  91.       return theLoc - [memberRect.width / 2, memberRect.height / 2]
  92.     #topcenter:
  93.       return theLoc - [memberRect.width / 2, 0]
  94.     #topright:
  95.       return theLoc - [memberRect.width, 0]
  96.     otherwise:
  97.       return theLoc
  98.   end case
  99. end
  100.  
  101. on DisplayText_Enroll me, enrollList
  102.   if ilk(enrollList) <> #list then
  103.     return me
  104.   end if
  105.   if not enrollList.count() then
  106.     enrollList.append(me)
  107.   else
  108.   end if
  109.   return enrollList
  110. end
  111.  
  112. on DisplayText_SetText me, thestring, theLoc, theAlignment
  113.   if not stringp(thestring) then
  114.     ErrorAlert(me, #invalidString, thestring)
  115.     thestring = string(thestring)
  116.   else
  117.     case ilk(theLoc) of
  118.       #void, #point:
  119.       otherwise:
  120.         ErrorAlert(me, #invalidPoint, theLoc)
  121.         theLoc = point(0, 0)
  122.     end case
  123.   end if
  124.   if (thestring = EMPTY) and (myDisplayType = #tooltip) then
  125.     mySprite.loc = myOffStageLoc
  126.     mySprite.locZ = myoriginallocz
  127.   else
  128.     myMember.text = thestring
  129.     if myDisplayType = #tooltip then
  130.       memberRect = BestRect(me, thestring)
  131.       myMember.rect = memberRect
  132.     else
  133.       memberRect = myMember.rect
  134.     end if
  135.     memberRect = memberRect + [0, 0, myWidthAdjust, myHeightAdjust]
  136.     if myDisplayType = #tooltip then
  137.       mySprite.locZ = the maxinteger
  138.       if ilk(theLoc) <> #point then
  139.         theLoc = point(0, 0)
  140.       end if
  141.       theLoc = GetTopLeft(me, theLoc, theAlignment, memberRect)
  142.       stageWidth = (the activeWindow).rect.right - (the activeWindow).rect.left
  143.       stageHeight = (the activeWindow).rect.bottom - (the activeWindow).rect.top
  144.       maxH = stageWidth - memberRect.width
  145.       maxV = stageHeight - memberRect.height
  146.       theLoc[1] = max(0, min(theLoc[1], maxH))
  147.       theLoc[2] = max(0, min(theLoc[2], maxV))
  148.       theLoc = theLoc + myMember.regPoint
  149.       mySprite.loc = theLoc
  150.     else
  151.       lastChar = thestring.char.count
  152.       textHeight = charPosToLoc(myMember, lastChar)[2]
  153.       if textHeight > mySprite.height then
  154.         myMember.boxType = #scroll
  155.       else
  156.         myMember.boxType = #fixed
  157.       end if
  158.     end if
  159.   end if
  160. end
  161.  
  162. on DisplayText_GetReference me
  163.   return me
  164. end
  165.  
  166. on ErrorAlert me, theError, data
  167.   behaviorName = string(me)
  168.   delete word 1 of behaviorName
  169.   delete char -30001 of behaviorName
  170.   delete char -30001 of behaviorName
  171.   case theError of
  172.     #invalidString:
  173.       if the runMode = "Author" then
  174.         message = substituteStrings(me, "BEHAVIOR ERROR: Frame ^0, Sprite ^1" & RETURN & "Behavior ^2" & RETURN & RETURN & "The DisplayText_SetText handler could not treat the following as a string:" & RETURN & RETURN & "^3", ["^0": the frame, "^1": me.spriteNum, "^2": behaviorName, "^3": data])
  175.         alert(message)
  176.       end if
  177.     #invalidPoint:
  178.       if the runMode = "Author" then
  179.         message = substituteStrings(me, "BEHAVIOR ERROR: Frame ^0, Sprite ^1" & RETURN & "Behavior ^2" & RETURN & RETURN & "The DisplayText_SetText handler could not treat the following as a point:" & RETURN & RETURN & "^3", ["^0": the frame, "^1": me.spriteNum, "^2": behaviorName, "^3": data])
  180.       end if
  181.   end case
  182. end
  183.  
  184. on substituteStrings me, parentString, childStringList
  185.   i = childStringList.count()
  186.   repeat while i
  187.     tempString = EMPTY
  188.     dummyString = childStringList.getPropAt(i)
  189.     replacement = childStringList[i]
  190.     lengthAdjust = dummyString.char.count - 1
  191.     repeat while 1
  192.       position = offset(dummyString, parentString)
  193.       if not position then
  194.         parentString = tempString & parentString
  195.         exit repeat
  196.         next repeat
  197.       end if
  198.       if position <> 1 then
  199.         tempString = tempString & parentString.char[1..position - 1]
  200.       end if
  201.       tempString = tempString & replacement
  202.       delete parentString.char[1..position + lengthAdjust]
  203.     end repeat
  204.     i = i - 1
  205.   end repeat
  206.   return parentString
  207. end
  208.  
  209. on isOKToAttach me, aSpriteType, aSpriteNum
  210.   case aSpriteType of
  211.     #graphic:
  212.       return getPos([#field, #text], sprite(aSpriteNum).member.type) <> 0
  213.     #script:
  214.       return 0
  215.   end case
  216. end
  217.  
  218. on getPropertyDescriptionList me
  219.   if not (the currentSpriteNum) then
  220.     exit
  221.   end if
  222.   return [#myDisplayType: [#comment: "Display Text sprite behaves as a", #format: #string, #default: "status bar (fixed size and position)", #range: ["status bar (fixed size and position)", "tooltip (dynamic size and position)"]]]
  223. end
  224.